/*
 * Copyright (c) 2009 Jostein Austvik Jacobsen
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package no.yr;

import java.text.DateFormat;
import java.util.Date;
public class WeatherTabular implements Comparable<WeatherTabular> {
	public enum Period { NIGHT, MORNING, DAY, EVENING, UNKNOWN };
	public enum Symbol { SUN, FAIR, PARTLY_CLOUDY, CLOUDY, RAIN_SHOWERS,
						 RAIN_SHOWERS_WITH_THUNDER, SLEET_SHOWERS,
						 SNOW_SHOWERS, RAIN, HEAVY_RAIN, RAIN_AND_THUNDER,
						 SLEET, SNOW, SNOW_AND_THUNDER, FOG,
						 SUN_POLAR_NIGHT, PARTLY_CLOUDY_POLAR_NIGHT,
						 RAIN_SHOWERS_POLAR_NIGHT,
						 SNOW_SHOWERS_POLAR_NIGHT, UNKNOWN };
	public enum Direction { N, NNE, NE, ENE, E, ESE, SE, SSE,
							S, SSW, SW, WSW, W, WNW, NW, NNW, UNKNOWN };
	
	public Date from, to;
	public Period period;
	public Symbol symbol;
	public Direction windDirection;
	public WeatherText text;
	public String symbolName, windDirectionName, windSpeedName,
				  temperatureUnit, pressureUnit;
	public double precipitation, windDirectionDeg, windSpeedMps,
				  temperature, pressure;
	
	public String periodAsText() {
		switch(period) {
			case NIGHT: return "natt";
			case MORNING: return "morgen";
			case DAY: return "dag";
			case EVENING: return "kveld";
			default: return "ukjent";
		}
	}
	
	public String symbolAsText() {
		switch(symbol) {
			case SUN: return "sol";
			case FAIR: return "lettskyet";
			case PARTLY_CLOUDY: return "delvis skyet";
			case CLOUDY: return "skyet";
			case RAIN_SHOWERS: return "regnbyger";
			case RAIN_SHOWERS_WITH_THUNDER: return "regnbyger med torden";
			case SLEET_SHOWERS: return "sluddbyger";
			case SNOW_SHOWERS: return "snøbyger";
			case RAIN: return "regn";
			case HEAVY_RAIN: return "kraftig regn";
			case RAIN_AND_THUNDER: return "regn og torden";
			case SLEET: return "sludd";
			case SNOW: return "snø";
			case SNOW_AND_THUNDER: return "snø og torden";
			case FOG: return "tåke";
			case SUN_POLAR_NIGHT: return "klarvær";
			case PARTLY_CLOUDY_POLAR_NIGHT: return "delvis skyet";
			case RAIN_SHOWERS_POLAR_NIGHT: return "regnbyger";
			case SNOW_SHOWERS_POLAR_NIGHT: return "snøbyger";
			default: return "ukjent";
		}
	}
	
	public String directionAsText() {
		switch(windDirection) {
			case N: return "nord";
			case NNE: return "nord-nordøst";
			case NE: return "nordøst";
			case ENE: return "øst-nordøst";
			case E: return "øst";
			case ESE: return "øst-sørøst";
			case SE: return "sørøst";
			case SSE: return "sør-sørøst";
			case S: return "sør";
			case SSW: return "sør-sørvest";
			case SW: return "sørvest";
			case WSW: return "vest-sørvest";
			case W: return "vest";
			case WNW: return "vest-nordvest";
			case NW: return "nordvest";
			case NNW: return "nord-nordvest";
			default: return "ukjent";
		}
	}
	
	public int compareTo(WeatherTabular o) {
		return from.compareTo(o.from);
	}
	
	// Useful for debugging
	public void printDataTree() {
		DateFormat format = DateFormat.getInstance();
		System.out.println(
				"\tfrom: "+format.format(from)+" to: "+format.format(to)+
				"\n\t\tperiod: "+periodAsText()+
				"\n\t\tsymbol: "+symbolAsText()+
				"\n\t\twindDirection: "+directionAsText()
		);
		if (text == null) System.out.println("\t\ttext forecast: null");
		else text.printDataTree();
		System.out.println(
				"\t\tsymbolName: "+symbolName+
				"\n\t\twindDirectionName: "+windDirectionName+
				"\n\t\twindDirectionDeg: "+windDirectionDeg+
				"\n\t\twindSpeedmps: "+windSpeedMps+
				"\n\t\twindSpeedName: "+windSpeedName+
				"\n\t\ttemperatureUnit: "+temperatureUnit+
				"\n\t\ttemperature: "+temperature+
				"\n\t\tpressureUnit: "+pressureUnit+
				"\n\t\tpressure: "+pressure+
				"\n\t\tprecipitation: "+precipitation
		);
	}
}
